#include <bits/stdc++.h>

#define ll long long
const int INF = 1e9;
using namespace std;
int dp[1003][1003] = { 0 };

void solve() {
	int r = 0;
	cin >> r;
	for (int i = 1; i <= r; i++) {
		for (int j = 1; j <= i; j++) {
			cin >> dp[i][j];
		}
	}
	for (int i = 1; i <= r; i++)
		for (int j = 1; j <= i; j++) {
			dp[i][j] = max(dp[i-1][j],dp[i - 1][j - 1]) + dp[i][j];
		}
	int ans = -1;
	for (int i = 1; i <= r; i++) {
		if (ans < dp[r][i]) {
			ans = dp[r][i];
		}
	}
	cout << ans;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	solve();
	return 0;
}